package k.daniel.databindingdemo;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import k.daniel.databindingdemo.bean.UserBean;
import k.daniel.databindingdemo.databinding.ActivityBaseObservableBinding;

public class ObservableFieldActivity extends AppCompatActivity {

    private UserBean userBean;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityBaseObservableBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_base_observable);
        userBean = new UserBean("daniel", "zhao", 25, true);
        binding.setUser(userBean);
        new Thread(new Runnable() {
            @Override
            public void run() {

               while (true)
               {
                   userBean.age.set(userBean.age.get()+1);
                   System.out.println("age is changed.");
                   try {
                       Thread.sleep(1000);
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
               }
            }
        }).start();
    }
}
